﻿using LiveCharts;
using LiveCharts.Wpf;
using Power.Models;
using Power.View.Report;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace Power.ViewModel.Report
{
    /// <summary>
    /// 缺陷种类图
    /// </summary>
    public class DefectTypeChartsViewModel : ReportTableBase
    {
        public List<DefectKindChartData> Data { get; set; }
        private DefectTypeCharts model;
        public DefectTypeChartsViewModel(DefectTypeCharts model)
        {
            this.model = model;
            Data = new List<DefectKindChartData>()
            {
                new DefectKindChartData(){ DefectName = "种类1",Percent = 1},
                new DefectKindChartData(){ DefectName = "种类2",Percent = 2},
                new DefectKindChartData(){ DefectName = "种类3",Percent = 3},
                new DefectKindChartData(){ DefectName = "种类4",Percent = 4},
            };

            Init();
        }

        public void Init()
        {
            var chart = this.model.chart;
            var values = new ChartValues<double>();
            foreach (var item in Data)
            {
                values.Add(item.Percent);
            }

            chart.Series = new SeriesCollection
            {
                new ColumnSeries
                {
                    Values = values
                }
            };
           
            chart.AxisX.Add(new Axis()
            {
                Separator = new LiveCharts.Wpf.Separator()
                {
                    Step = 1
                },
                Labels = Data.Select(p=>p.DefectName).ToList()
            });
        }
    }
}
